<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/api/inc.jsp"%>
<script type="text/javascript">
function sub(){
	if(!$('#oauthForm').form('validate')){
		$('#content-result').html('');
		$('#content-now-result').html('');
		return false;
	}
	var json = formToJsonStr('oauthForm');
	if(!json){
		$('#content-result').html('');
		$('#content-now-result').html('');
		return false;
	}
	$('#content-result').html(writeJson(json));
	$.post('<c:url value="/oauth2/getAccessToken?r="/>'+Math.random(), formToJson('oauthForm'), function(data){
		if(!data || !data.success_response && !data.error_response){
			$('#content-result').html('');
			$('#content-now-result').html('');
			return;
		}
		$('#content-now-result').html(writeJson(JSON.stringify(data)));
		if(data.success_response && data.success_response.result){
			var result = data.success_response.result;
			if(result && result[0] && result[0].accesstoken){
				$.cookie('uop_open_accesstoken', result[0].accesstoken, {path: '<c:url value="/api/"/>'});
			}
		}
	}, 'json');
}
</script>
<body>
<%@ include file="/api/header.jsp"%>
<div class="container grid-s165m0">
	<div class="col-main bg_line">
		<div class="main-wrap">
			<div class="api-detail-bd" id="bd">
					<div>
						<h2 class="head-title" id="result">
							<img src="<c:url value='/api/images/tri_down.png'/>" style="cursor: pointer; margin-right: 5px;" onclick="changeHide(this,'content-submit')">输入参数
						</h2>
						<form id="oauthForm">
							<div id="content-submit">
								<table class="api-table" cellspacing="0">
									<thead>
										<tr>
											<th width="20%" class="left">参数名</th>
											<th width="15%" class="middle">类型</th>
											<th width="15%" class="middle">是否必填</th>
											<th width="20%" class="left">示例值</th>
											<th width="30%" class="left">说明</th>
										</tr>
									</thead>
									<tbody>
										<tr class="odd">
											<td class="left">clientId</td>
											<td class="middle">String</td>
											<td class="middle"><a style="color:red;">必填</a></td>
											<td class="middle"><input type="text" value="" style="width: 300px;" name="clientId" id="clientId" class="easyui-validatebox" data-options="required:true"/></td>
											<td class="left">客户端ID</td>
										</tr>
										<tr class="odd">
											<td class="left">clientSecret</td>
											<td class="middle">String</td>
											<td class="middle"><a style="color:red;">必填</a></td>
											<td class="middle"><input type="text" value="" style="width: 300px;" name="clientSecret" id="clientSecret" class="easyui-validatebox" data-options="required:true"/></td>
											<td class="left">客户标识</td>
										</tr>
										<tr class="odd">
											<td class="middle" colspan="5"><input type="button" class="button" onclick="sub()" value="-提交-"  style="width: 100px;"/></td>
										</tr>
									</tbody>
								</table>
							</div>
						</form>
					</div>
			</div>
			<div>
				<h2 class="head-title" id="result">
					<img src="<c:url value='/api/images/tri_down.png' />" style="cursor: pointer; margin-right: 5px;" onclick="changeHide(this,'content-result')">
					提交的参数为：
				</h2>
				<div id="content-result"></div>
			</div>
			<div>
				<h2 class="head-title" id="now_result" >
					<img src="<c:url value='/api/images/tri_down.png' />" style="cursor: pointer; margin-right: 5px;" onclick="changeHide(this,'content-now-result')">
					当前返回结果为：
				</h2>
				<div id="content-now-result" style="font-weight: bold;color: red;"></div>
			</div>
			<div>
				<h2 class="head-title" id="example">
					<img src="<c:url value='/api/images/tri_down.png' />" style="cursor: pointer; margin-right: 5px;" onclick="changeHide(this,'content-example')">
					返回示例
				</h2>
				<div id="content-example">
					<script type="text/javascript">
						var success = '{"success_response":{"code": "sys.success","msg": "操作成功","result": [{"accesstoken": "fd50f35ae81c4ca12974efd48ffb1289","exprie_in": "31536000"}]}}';
						var error = '{"error_response": {"code": "oauth.fail","msg": "授权失败"}}';
						document.write('<p class="data-format">成功示例:</p>');
						document.write(writeJson(success));
						document.write('<p class="data-format">失败示例:</p>');
						document.write(writeJson(error));
					</script>
				</div>
			</div>
		</div>
	</div>
	<%@ include file="/api/order/left.jsp"%>
</div>
</body>